Classwork 1¶
INSERT YOUR NAME HERE
Directions: Add work to this notebook to solve the problems below.
Be careful to name the objects you create as described in the problem. Some problems may include some tests you can run to test your code.
This code below is used to conduct some of the provided tests. Execute it before working on the problems.
def _pass(s):
s = s.replace('\n','<br/>')
from IPython.display import HTML
display(HTML(f'<span style="color: darkgreen; ">{s}</span>'))
_pass('Results of a successful test will be printed like this.')
def _fail(s, stop=True):
s = s.replace('\n','<br/>')
from IPython.display import HTML
display(HTML(f'<span style="color: red; font-weight: bold; ">{s}</span>'))
if stop:
raise ValueError('You failed a test')
_fail('''Results of a failed test will be printed like this.
Typically a ValueError will also be raised, causing futher execution to stop.''', stop=False)
Standard imports¶
import numpy as np
1. The 2-adic solenoid¶
Let $D = \{(a,b,t) \in \mathbb R^3:~\text{$a^2+b^2 \leq 1$ and $0 \leq t < 2 \pi$}\}.$ We think of this as a solid torus (donut) by identifying $(a,b,0)$ with $(a,b,1)$. Indeed, if $$g:D \to \mathbb R^3; \quad (a,b,t) \mapsto \big((2+a)\cos(t), (2+a)\sin(t), b\big),$$ then this identification is made and the image $g(D)$ is a solid torus.
Part (a). Write $g$ as a Python function. Plot the boundary of $g(D)$. You might want to use parametric_plot3d
(see the sage reference or class notes from Oct 16th). (Hint: Pass symbolic variables to $g$ to get something you can plot.)
Consider the function $f:D \to D$ given by $$(a,b,t) \mapsto \left(\frac{3}{8} \, a + \frac{1}{2} \, \cos\left(t\right), \frac{3}{8} \, b + \frac{1}{2} \, \sin\left(t\right), 2 \, t\right),$$ where in the last coordinate we work modulo $2 \pi$. (You can ignore this, because whenever we use $t$ we will be applying $\cos$ or $\sin$ to it.)
Part (b). Write $f$ as a Python function. Plot the boundary of $g \circ f(D)$ together with the half of the boundary of $g(D)$ where $b \leq 0$. Use different colors if possible and make it look as nice as possible. (Hint: The star operator is your friend when composing Python functions.)
The map $h =g \circ f \circ g^{-1}$ is a map from the solid torus $g(D)$ into itself. The associated attractor is $$\Lambda = \bigcap_{n \geq 0} h^n(D).$$ The object $\Lambda$ is called the $2$-adic solenoid. (You may learn about it in dynamics class.) As a topological space, it locally looks like the product of an interval and a Cantor set.
We will plot some approximates. Let $N \geq 1$ represent a number of points to plot, and let $$\gamma(t)=(0,0,t) \quad \text{for $t \in [0,1]$}.$$ Then $\gamma$ wraps around the center of the solid torus in $(a,b,t)$-coordinates.
Part (c). Write a function solenoid_approx(N,k)
which given $N \geq 1$ and $k \geq 0$, returns three Numpy arrays. You should create a numpy array for $t$ which has $N$ points spaced within $[0,2 \pi]$. Then compute and return the triple of Numpy arrays
$$(x,y,z) = g \circ f^k \circ \gamma(t).$$
Use line3d
and zip
to plot the resulting curves for $N \geq 2000$ and $k \in \{0,1,2,3,4,5\}$. (Hints: Make sure you are not using the 'object'
dtype in your Numpy arrays. You'll need to double the number of points in a plot whenever you increase $k$ by one.)
2. Velocity vectors on the solenoid¶
We will estimate velocity vectors for the curves making up the solenoid using numerical differentiation. A natural (local) time parameter on the curve is given by the $t$ coordinate, which takes values in $[0,2pi)$.
Note that the function $f$ doubles the $t$ parameter. So, when we apply $f$ the time spacing between point on our curves doubles. As in the previous part, we approximate the $2$-adic solenoid $\Lambda$ by curves
$$\big(x(s), y(s), z(s)\big) = g \circ f^k \circ \gamma(s).$$
Approximations were returned by solenoid_approx
.
Write a function solenoid_derivative_approx(N,k)
which takes as input a number of points $N \geq 2$ and a $k \geq 0$ and returns three Numpy arrays containing approximations for the quantities:
$$\frac{dx(s)}{dt}=\frac{1}{2^k} \cdot \frac{dx(s)}{ds}, \quad
\frac{dy(s)}{dt}=\frac{1}{2^k} \cdot \frac{dy(s)}{ds}, \quad
\frac{dz(s)}{dt}=\frac{1}{2^k} \cdot \frac{dz(s)}{ds}$$
at $N$ points around the circle. Here $s$ is the parameter being input to $\gamma$ and $t$ is the parameter coming from the coordinates on $D$. Because $f$ doubles the $t$-coordinate, we have $t = 2^k s \pmod{2 \pi}$.
Plot the curve of velocity vectors for various small values of $k$.
If possible plot each of the three quantities above as a function of the $t$-coordinate on the image $g(D)$. For example, plot $t$ versus $\frac{dx(s)}{dt}$.